package regions

import (
	"context"
	"product/common/enumeration"

	"product/settings/serve/internal/svc"
	"product/settings/serve/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteRegionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewDeleteRegionLogic delete regions
func NewDeleteRegionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRegionLogic {
	return &DeleteRegionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteRegionLogic) DeleteRegion(req *types.DeleteAreaReq) (resp *types.DeleteAreaResp, err error) {
	if req.ID <= 0 {
		return &types.DeleteAreaResp{
			Code:    enumeration.ProcessingFailed,
			Message: "参数错误",
		}, nil
	}
	err = l.svcCtx.RegionsModel.Delete(l.ctx, req.ID)
	if err != nil {
		return &types.DeleteAreaResp{
			Code:    enumeration.ProcessingFailed,
			Message: "删除失败",
		}, nil
	}
	return &types.DeleteAreaResp{
		Code:    enumeration.ProcessingSuccess,
		Message: "删除成功",
	}, nil
}
